<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title>AllyFolio | Notifications Settings </title>
<?php include_once("common_script_inclusions.php"); ?>
<!-- for checkbox on-off styling-->
<link rel="stylesheet" href="css/jquery.switchButton.css"/>
<style>			
    .switch-wrapper {
        display: inline-block;
        position: relative;
        top: 3px;
    }
    
    
    .slider.demo .switch-button-label {
        font-size: 20px;
    }
</style>
<!-- for checkbox on-off styling-->

</head>
<body>
<?php
require_once("includes/pagetop.php");
if(isset($_SESSION['Allyfolio_User_ID']))
{   
    if($_SESSION['Allyfolio_User_ID']<0){
        redirect("accountblocked.php");    
    }
}
else{
    redirect("index.php");
}
include_once("updates/CommonFeatures.php");

$loggedUserObj=new UserDetails();
if (!isset($_SESSION["User_details"])){
    $_SESSION["Privacy_Settings"]=$loggedUserObj->getUserPrivacyDetails($_SESSION["Allyfolio_User_ID"]);
}
//echo "<pre>";
//print_r($_SESSION["Privacy_Settings"]);
?>
	<div id="main_wrapper">
    <!--=================Header Start=======================-->
	<div class="wrapper row1">
	<div class="header">
    	<div class="log_button">
		<table width="744" border="0" style="margin-top:5px;">
			<tr>
				<td width="24">
					<a href="#"><img src="images/navico_1.png" /></a>				</td>
				<td width="36">
					<a href="#"><img src="images/navico_2.png" /></a>				</td>
				<td width="26">
					<a href="#"><img src="images/navico_3.png" /></a>				</td>
				<td width="30">
					<a href="#"><img src="images/navico_4.png" /></a>				</td>
					<td width="594">
					<!--<ul class="dn_txt3">
						<li><img src="images/dna_txt_right.png" /></li>
						<li><input type="text" class="dna_txt2" /></li>
						<li><img src="images/dna_txt_left.png" /></li>
					</ul>-->
					
					</td>
			</tr>
		  </table>
		</div>
		
       
    	
        <a href="index.html" class="logo"></a>
    </div>
    <div class="clearfix"></div>  
    
    
    </div>
    <div class="clearfix"></div>
    <!--=================Header end=======================-->
    
    
    
    <!--=================Body Contain Start=======================-->
    <div class="wrapper">
      <div class="header acSetting">
          <h1>Settings</h1>
            <table cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <td style="vertical-align: top;">
                          <div >
                          <?php  
                          include_once("settings_menu.php");
                          include_once("includes/common_snippets.php");
                          ?>
                          </div>
                    </td>
                    <td style="vertical-align: top;">    
                        <form name="frmnotificationsettings" id="frmnotificationsettings" action="ajax/generic_crudoperations.php"></form>
                        <?php
                        $oDropfilters= new CGetFilters();
                        $clusterDrops=$oDropfilters->getClusters($_SESSION["Allyfolio_User_ID"],1);                        
                        $privacyTypes=$oDropfilters->getFilters("privacy_types",1,true);
                        $myclusteretting="";
                        if (!empty($_SESSION["Privacy_Settings"])) {
                            $myclusteretting = trim($_SESSION["Privacy_Settings"]["hide_notifications_from_cluster_ids"]);
                        }
                        $ignoreclusteridArr=array();
                        if(strlen($myclusteretting)>0){
                            if(strstr($myclusteretting,",")){
                                $ignoreclusteridArr=explode(",",$myclusteretting);
                            }
                            else{
                                $ignoreclusteridArr[0]=$myclusteretting;
                            }
                        }
                        ?> 
                         <div class="acSettingSecR">
                         <div class="fieldSec">
                            <div style="float: left;">
                                <label class="w316">Cluster Notification</label>
                            </div>
                            
                            <div style="float: left;">
                            <?php
                            foreach($clusterDrops as $mycluster){
                                
                                $checkedid=false;
                                if(in_array($mycluster["Cluster_ID"],$ignoreclusteridArr)){
                                    $checkedid=true;
                                }
                                //echo "clusterid=".$mycluster["Cluster_ID"]."= ".$checkedid;
                            ?>
                            <br />
                                <div class="slider demo" id="slider-2" style="float: left;">
                            		<input type="checkbox" id="chk_<?php echo $mycluster["Cluster_ID"]; ?>" value="<?php echo (($checkedid==true)?1:0);?>" class="<?php echo $mycluster["Cluster_ID"]; ?>"/>
                            	</div>
                                <!-- 
                                <input type="checkbox" name="chk_<?php echo $mycluster["Cluster_ID"]; ?>" id="chk_<?php echo $mycluster["Cluster_ID"]; ?>" class="<?php echo $mycluster["Cluster_ID"]; ?>" <?php echo ($checkedid==true)?"checked='true'":""; ?>/> <?php echo $mycluster["Cluster_Name"]; ?>
                                -->
                            <?php
                            }
                            ?> 
                            </div>
                         </div>
                         <div class="fieldSec">
                            <br />
                            <label class="w316">Join pages notification</label> 
                            <select id="join_pages_notifications" id="join_pages_notifications">
                                    <?php
                                    $myprivacysetting=0;
                                    if (!empty($_SESSION["Privacy_Settings"])) {
                                        $myprivacysetting = trim($_SESSION["Privacy_Settings"]["join_pages_notifications"]);
                                    }
                                    if(is_numeric($myprivacysetting) && $myprivacysetting>0){
                                        $defaultSelected=$myprivacysetting;
                                    }
                                    else{
                                        $defaultSelected=1; //privacy type assigned    
                                    }
                                    foreach($privacyTypes as $privacyType){
                                        if($privacyType["ID"]==$defaultSelected){
                                            $selected=true;
                                        }
                                        else if($privacyType["keyword"]=="public"){
                                            $selected=true;
                                        }
                                        else{
                                            $selected=false;
                                        }
                                        
                                        ?>
                                        <option value="<?php echo $privacyType["ID"] ?>" <?php if($selected){  ?>selected="true" <?php } ?> >
                                            <?php echo $privacyType["Privacy_Type_Title"]; ?> 
                                        </option>
                                        <?php   
                                        
                                    }
                                    ?>
                                </select>
                         </div>
                         <div class="fieldSec">
                            <label class="w316">Enclose in join pages notification</label> 
                            <select id="enclose_in_join_pages_notifications" id="enclose_in_join_pages_notifications">
                                    <?php
                                    $myprivacysetting=0;
                                    if (!empty($_SESSION["Privacy_Settings"])) {
                                        $myprivacysetting = trim($_SESSION["Privacy_Settings"]["enclose_in_join_pages_notifications"]);
                                    }
                                    if(is_numeric($myprivacysetting) && $myprivacysetting>0){
                                        $defaultSelected=$myprivacysetting;
                                    }
                                    else{
                                        $defaultSelected=1; //privacy type assigned    
                                    }
                                    foreach($privacyTypes as $privacyType){
                                        if($privacyType["ID"]==$defaultSelected){
                                            $selected=true;
                                        }
                                        else if($privacyType["keyword"]=="public"){
                                            $selected=true;
                                        }
                                        else{
                                            $selected=false;
                                        }
                                        
                                        ?>
                                        <option value="<?php echo $privacyType["ID"] ?>" <?php if($selected){  ?>selected="true" <?php } ?> >
                                            <?php echo $privacyType["Privacy_Type_Title"]; ?> 
                                        </option>
                                        <?php
                                        
                                    }
                                    ?>
                                </select>
                         </div>
                     
                         </div>
                    </td>
                </tr>
            </table>
     </div>
     </div>
     
    
 	
	
	 
    </div>
    
    
    <div class="clearfix"></div>
    <script type="text/javascript">
    /*
    $("input[type=checkbox]").change(function(e){
        var idClicked = e.target.id;
        var clusterselected=$( "input[type=checkbox]:checked" );
        var selectedClustersLength=clusterselected.length;
        var selectedClusters="";
        for(var i=0;i<selectedClustersLength;i++){
            //alert($(clusterselected[i]).attr("id"));
            selectedClusters+= $(clusterselected[i]).attr("class")+",";
        }
        selectedClusters=selectedClusters.substr(0,selectedClusters.length-1);
        alert(selectedClusters);
        var clusterid=$("#"+idClicked).attr("class");
        changePrivacySettings("hide_notifications_from_cluster_ids",selectedClusters);
    });
    */
    $("select").change(function(e){
        var idClicked = e.target.id;
        changePrivacySettings(idClicked,$("#"+idClicked).val());
    });

    function changePrivacySettings(sFor,iVal){
        var urlstr = $("#frmnotificationsettings").attr( "action" );
        //alert("sfor: "+sFor+" iVal "+iVal);
        $.ajax({
    	  	type: "POST",
    	  	url: urlstr,
    	  	cache: false,
    	  	data: { 
    	  	         "actiontype":"update_userprivacy_settings",   
    	  	         "sFor": sFor,                                     
                     "iVal": iVal
                  } 
        })
    	.done(function( data ) {	
    	   //alert(data);
    	   var jsonParsed=$.parseJSON(data);
            console.log(jsonParsed);
            /*if(document.getElementById("errconsole")){
                document.getElementById("errconsole").innerHTML=data;
            }*/
            if(!isNaN(jsonParsed.err)){ //means have some code
                switch(parseInt(jsonParsed.err)){
                    case 200:
                            //alert(jsonParsed.msg);
                            break;
                    default:
                            alert(jsonParsed.msg);
                            break;
                }
            }
    	})
    	.fail(function(msg) { 
    		console.log(msg);
    //		alert("error"); 
    	})
        .always(function() { 
    		//alert("complete"); 
    	});
    }
</script>
<!-- for checkbox on-off actions-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script src="js/jquery.switchButton.js"></script>
<script type="text/javascript">	
	$(function() {
	   <?php
       foreach($clusterDrops as $mycluster){            
            $checkedid=false;
            if(in_array($mycluster["Cluster_ID"],$ignoreclusteridArr)){
                $checkedid=true;
            }
       ?> 
       $("#slider-2.demo #chk_<?php echo $mycluster["Cluster_ID"]; ?>").switchButton({
          width: 40,
          height: 20,
          button_width: 20,
          labels_placement: "right",
          on_label: "<?php echo $mycluster["Cluster_Name"]; ?>",
          off_label: "<?php echo $mycluster["Cluster_Name"]; ?>",
          checked: <?php echo ($checkedid)?'true':'false'; ?>
        });
       <?php
       }
       ?>
    });
	
    $(document).ready(function(){
		$("input[type=checkbox]").change(function(e) {
            var idClicked = e.target.id;
            var clusterselected=$( "input[type=checkbox]:checked" );
            var selectedClustersLength=clusterselected.length;
            var selectedClusters="";
            for(var i=0;i<selectedClustersLength;i++){
                //alert($(clusterselected[i]).attr("id"));
                selectedClusters+= $(clusterselected[i]).attr("class")+",";
            }
            selectedClusters=selectedClusters.substr(0,selectedClusters.length-1);
            //alert(selectedClusters);
            var clusterid=$("#"+idClicked).attr("class");
            changePrivacySettings("hide_notifications_from_cluster_ids",selectedClusters);
		    //console(e);
		});
	});
</script>
        
<!-- for checkbox on-off actions-->

 </body>
</html>
